package _3_异常处理._1_Java的异常;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class JavaException {

    public static void main(String[] args) {
        byte[] bytes = toGBK("中文");
        System.out.println(Arrays.toString(bytes));
    }

    static byte[] toGBK(String s){
        try {
            //用指定编码转换String为byte[]
            return s.getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            //尝试使用默认默认编码
            return s.getBytes();
        }
    }
}
